#ifndef TRIANGLE_H
#define TRAINGLE_H

#include "Geometry.h"
#include <stdio.h>

class WTriangle: public Geometry {
public:
    vec3 p1, p2, p3;
    /* used for surface reconstruction only */
    vec3 n1, n2, n3;
    /* indices of the normals for the grid */
    int i1, i2, i3;
    vec3 normal;
    bool surface;

    WTriangle() {
        name = "Triangle";
        surface = false;
        i1 = i2 = i3 = -1;
    }

    ~WTriangle() {
        printf("deleted\n");
    }

    Symbol parse(ifstream &file, Symbol curToken);
    bool intersect(Ray *r);
    vec3 getNormal(Ray *r);
    vec3 genRandomPoint(vec3 look, int cur, int lim);

    void print() {
        printf("Triangle:\n\tCorner 1: %f %f %f\n\tCorner 2: %f %f %f"
                "\n\tCorner3: %f %f %f\n",
                p1.x, p1.y, p1.z,
                p2.x, p2.y, p2.z,
                p3.x, p3.y, p3.z);

        Geometry::print();
    }

    AABB *generateAABB();

    int type() {
        return 3;
    }
};

#endif
